Coverage Report

Created: 2025-11-02 11:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
D:\a\csshw\csshw\src\daemon\workspace.rs
Line
Count
Source
1
use crate::utils::windows::WindowsApi;
2
use windows::Win32::UI::WindowsAndMessaging::{
3
    SM_CXFIXEDFRAME, SM_CXMAXIMIZED, SM_CXSIZEFRAME, SM_CYFIXEDFRAME, SM_CYMAXIMIZED,
4
    SM_CYSIZEFRAME,
5
};
6
7
/// The available workspace area on the primary monitor
8
///
9
/// Also includes `fixed_frame` and `size_frame` attributes respecitvely indicating
10
/// the thickness of the frame around the perimeter of a window and the thickness
11
/// of the sizing border around the perimeter of a window.
12
///
13
/// <https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsystemmetrics>
14
#[derive(Clone, Copy, Debug)]
15
pub struct WorkspaceArea {
16
    /// The `x` coordinate of the workspace area in pixels.
17
    /// From the top left of the screen.
18
    pub x: i32,
19
    /// The `y` coordinate of the workspace area in pixels.
20
    /// From the top left of the screen.
21
    pub y: i32,
22
    /// The width in pixels of the workspace area.
23
    pub width: i32,
24
    /// The height in pixels of the workspace area.
25
    pub height: i32,
26
    /// The thickness of the frame around the perimeter of a window on the x-axis.
27
    pub x_fixed_frame: i32,
28
    /// The thickness of the frame around the perimeter of a window on the y-axis.
29
    pub y_fixed_frame: i32,
30
    /// The thickness of the sizing border around the perimter of a window on the x-axis.
31
    pub x_size_frame: i32,
32
    /// The thickness of the sizing border around the perimter of a window on the y-axis.
33
    pub y_size_frame: i32,
34
}
35
36
/// Returns the available workspace area on the primary monitor in the specified scaling minus the space
37
/// occupied by the daemon console.
38
///
39
/// # Arguments
40
///
41
/// * `scaling`                 - The desired scaling for the workspace area. Physical or logical.
42
///                               This does not control which scaling is used by the system but only
43
///                               in which scalin the returned values are.
44
/// * `daemon_console_height`   - Height of the daemon console that will be substraced
45
///                               from the workspace area height.
46
///
47
/// # Returns
48
///
49
/// The available workspace area on the primary monitor in the specified scaling minus the space
50
/// occupied by the daemon console.
51
0
pub fn get_workspace_area<W: WindowsApi>(
52
0
    windows_api: &W,
53
0
    daemon_console_height: i32,
54
0
) -> WorkspaceArea {
55
0
    let workspace_width = windows_api.get_system_metrics(SM_CXMAXIMIZED) - 1;
56
0
    let workspace_height = windows_api.get_system_metrics(SM_CYMAXIMIZED) - 1;
57
0
    let x_fixed_frame = windows_api.get_system_metrics(SM_CXFIXEDFRAME);
58
0
    let y_fixed_frame = windows_api.get_system_metrics(SM_CYFIXEDFRAME);
59
0
    let x_size_frame = windows_api.get_system_metrics(SM_CXSIZEFRAME);
60
0
    let y_size_frame = windows_api.get_system_metrics(SM_CYSIZEFRAME);
61
0
    return WorkspaceArea {
62
0
        x: 0,
63
0
        y: 0,
64
0
        width: workspace_width,
65
0
        height: workspace_height - daemon_console_height,
66
0
        x_fixed_frame,
67
0
        y_fixed_frame,
68
0
        x_size_frame,
69
0
        y_size_frame,
70
0
    };
71
0
}